home *** CD-ROM | disk | FTP | other *** search
/ Super PC 35 / Super PC 35 (Shareware).iso / spc / WIN95 / CM95 / INTERNET.DLL / TEXT / WILTIME < prev   
Encoding:
Text File  |  1996-03-20  |  2.9 KB  |  119 lines

  1. szTitle = "ClockMan GetTime pgm"
  2. bOK = @TRUE
  3. szDial = "%dialupname%"
  4. szHost = "%timeserveraddr%"
  5. szErrDesc = ""
  6.  
  7.  
  8. ;Dial our host (unless user is on a direct connect)...
  9. hConn = 0
  10. if (szDial <> "")
  11.     hConn = SDialUp (szDial)
  12.     nErr = SGetLastErr ()
  13.     if (!hConn)
  14.         switch nErr
  15.             case @SErrNotFound
  16.             szErrDesc = "Couldn't connect to %szDial% - no such dial-up"
  17.  
  18.             case nErr ; <--default
  19.             szErrDesc = "Couldn't connect to %szDial% - error %nErr%"
  20.         endswitch
  21.         bOK = @FALSE
  22.         goto LogIt
  23.     endif
  24. endif
  25.  
  26. ; Create a socket...
  27. hSock = SOpen (@SBlocking)
  28. if (hSock==@SErrSocket)
  29.     nErr = SGetLastErr ()
  30.     szErrDesc = "Couldn't create socket - error %nErr%"
  31.     bOK = @FALSE
  32.     goto HangUp
  33. endif
  34.  
  35. ; Connect it up...
  36. nRet = SConnect (hSock, szHost, "time")
  37. if (nRet <> @TRUE)
  38.     nErr = SGetLastErr ()
  39.     switch nErr
  40.         case @SErrHostName
  41.         szErrDesc = "Host ""%szHost%"" not found. (Misspelled, or no longer exists.)"
  42.         break
  43.  
  44.         case 10060
  45.         szErrDesc = "Timed out trying to connect to ""%szHost%""."
  46.         break
  47.  
  48.         case @SErrBusy
  49.         szErrDesc = "Couldn't connect to ""%szHost%"".%@CRLF%(Server busy.)"
  50.         break
  51.  
  52.         case @SErrNoConn
  53.         szErrDesc = "Couldn't connect to ""%szHost%"".%@CRLF%(Server down, or they don't offer a time server.)"
  54.         break
  55.  
  56.         case nErr ; <--default
  57.         szErrDesc = "Couldn't connect to ""%szHost%"" - WinSock error %nErr%"
  58.     endswitch
  59.  
  60.     bOK = @FALSE
  61.     goto CloseSocket
  62. endif
  63.  
  64. ; Time server sent us the time immediately upon connect...
  65. dwRawTime = SRecvNum32 (hSock)
  66. dwPrevTime = CMGetSysTime ()
  67. if (!dwRawTime)
  68.     ; Oh, maybe they require a CR/LF first like RFC 868 claims they should?...
  69.     SSendLine (hSock, "")
  70.     dwRawTime = SRecvNum32 (hSock)
  71.     dwPrevTime = CMGetSysTime ()
  72. endif
  73.  
  74. if (!dwRawTime)
  75.     szErrDesc = "No response from time server @ ""%szHost%""."
  76.     bOK = @FALSE
  77. else
  78.     ; Immediately update our system time...
  79.     dwNewTime = dwRawTime - 2208988800; Convert to secs since 1/1/70 from 1/1/00
  80.     CMSetSysTime (dwNewTime)
  81. endif
  82.  
  83. ; If user hit Ctrl+Break, WIL will bring us here...
  84. :Cancel
  85.  
  86. ; Close the socket...
  87. :CloseSocket
  88. nRet = SClose (hSock)
  89.  
  90. ; Hang up...
  91. :HangUp
  92. if (hConn)
  93.     nRet = SHangUp (hConn)
  94. endif
  95.  
  96.  
  97. ; Log what we did...
  98. :LogIt
  99. if bOK == @TRUE
  100.     ; Finally, log the adjustment...
  101.     dwOffset = dwNewTime - dwPrevTime
  102.     if (dwOffset > 0)
  103.         szLog = "Turned the clock forward by %dwOffset% seconds"
  104.     else
  105.         if (dwOffset < 0)
  106.             dwOffset = -dwOffset
  107.             szLog = "Turned the clock back by %dwOffset% seconds"
  108.         else
  109.             szLog = "No adjustment needed to the system clock!"
  110.         endif
  111.     endif
  112. else
  113.     szLog = strcat ("Error attempting to adjust time:", @CRLF, szErrDesc)
  114. endif
  115.  
  116. CMLogMessage (szLog)
  117. Display (5, szTitle, szLog)
  118. ~
  119.